﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;

namespace ExamServer.Dao
{
    class BaseDao<T>
    {
        private ISession session;

        public BaseDao()
        {
            IsConnectionSuccess();
        }

        public bool IsConnectionSuccess()
        {
            try
            {
                session = (new Configuration()).Configure().BuildSessionFactory().OpenSession();
                return true;
            }
            catch (Exception e) {
                return false;
            }
        }

        public virtual T GetEntityById(int id)
        {
            return session.Get<T>(id);
        }
    }
}
